package com.cqc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }


    @Bean
    public CorsFilter corsFilter(){
        CorsConfiguration config=new CorsConfiguration();
        //允许的域 , 不要写 * ，否则 cookie 就无法使用了
        //config.addAllowedOrigin("*");
        config.addAllowedOriginPattern("*");
        // 是否发送 Cookie 信息
        config.setAllowCredentials(true);
        // 允许的请求方式，必须大写 org.springframework.http.HttpMethod
        config.addAllowedMethod("*");
        //允许的头
        config.addAllowedHeader("*");

        //添加映射路径，我们拦截一切请求
        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
        configSource.registerCorsConfiguration("/**",config);
        return new CorsFilter(configSource);
    }


}
